/* ----------------------------------------------------------------------------
* File: event_sink.cpp
*
* Desc: Event sink
*
* Created: 21/07/2011, by Alexey Korshunov
* ---------------------------------------------------------------------------- */
#include "event_sink.h"


namespace SkypeProxyManagement
{
	EventSink::EventSink(SkypeEventHandler* handler)
		: m_SkypeHandler(handler)
	{

	}

	void __stdcall EventSink::Command(SKYPE4COMLib::ICommand* pCommand)
	{
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnCommand(pCommand);
	}

	void __stdcall EventSink::Reply(SKYPE4COMLib::ICommand* pCommand)
	{
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnReply(pCommand);
	}

	void __stdcall EventSink::Error(SKYPE4COMLib::ICommand* pCommand, LONG Number, BSTR Description)
	{
		//_tprintf(_T("E(%d): %s\n"), pCommand->GetId(), (LPCTSTR)pCommand->GetReply());
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnError(pCommand, Number, Description);
	}

	void __stdcall EventSink::AttachmentStatus(SKYPE4COMLib::TAttachmentStatus Status)
	{
		//_tprintf(_T("Attachment status %d\n"), Status);
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnAttachmentStatus(Status);
	}

	void __stdcall EventSink::ConnectionStatus(SKYPE4COMLib::TConnectionStatus Status)
	{
		//_tprintf(_T("Connection status %d\n"), Status);
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnConnectionStatus(Status);
	}

	void __stdcall EventSink::UserStatus(SKYPE4COMLib::TUserStatus Status)
	{
		//_tprintf(_T("User status %d\n"), Status);
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnUserStatus(Status);
	}

	void __stdcall EventSink::OnlineStatus(SKYPE4COMLib::IUser* pUser, SKYPE4COMLib::TOnlineStatus Status)
	{
		//_tprintf(_T("User %s status %d\n"), (LPCTSTR)pUser->GetHandle(), Status);
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnOnlineStatus(pUser, Status);
	}

	void __stdcall EventSink::CallStatus(SKYPE4COMLib::ICall* pCall, SKYPE4COMLib::TCallStatus Status)
	{
		//_tprintf(_T("Call %d status %d\n"), pCall->GetId(), Status);
		switch(Status)
		{
		case SKYPE4COMLib::TCallStatus::clsInProgress:
		case SKYPE4COMLib::TCallStatus::clsRouting:
		case SKYPE4COMLib::TCallStatus::clsRinging:
		case SKYPE4COMLib::TCallStatus::clsFailed:
		case SKYPE4COMLib::TCallStatus::clsFinished:
			break;
		}

		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnCallStatus(pCall, Status);
	}

	void __stdcall EventSink::CallHistory()
	{
		//_tprintf(_T("Call history changed\n"));
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnCallHistory();
	}

	void __stdcall EventSink::Mute(VARIANT_BOOL Status)
	{      
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnMute(Status);
	}

	void __stdcall EventSink::MessageStatus(SKYPE4COMLib::IChatMessage* pMessage, SKYPE4COMLib::TChatMessageStatus Status)
	{
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnMessageStatus(pMessage, Status);
	}

	void __stdcall EventSink::MessageHistory(BSTR Username)
	{
		//_tprintf(_T("Message history changed %s\n"), (LPCTSTR)_bstr_t(Username));
		if (m_SkypeHandler != NULL)
			m_SkypeHandler->OnMessageHistory(Username);
	}
}